<!-- Student_FreeCourseChapterListNew.html -->
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
		<meta name="format-detection" content="telephone=no, email=no, date=no, address=no">
		<title>自由课程章节列表</title>
		<link rel="stylesheet" type="text/css" href="../../css/api.css" />
		<link rel="stylesheet" type="text/css" href="../../css/weui.min.css" />
		<link rel="stylesheet" type="text/css" href="../../css/mui.min.css" />
		<link rel="stylesheet" href="../../css/base.css"/>
		<link rel="stylesheet" href="../../css/CFNetPP_Base.css">
		<style type="text/css" media="screen">
			.noSign {
				width: auto;
			}
			.loadFailure {
				width: auto;
			}
			.chapter_cell_left_icon {
				height: 26px;
				margin-right: 10px;
				/*display:block;*/
			}
			.weui_cell_hd{
				height: 26px;
			}
			.weui_cell{
				padding: 15px;
			}
			.mui-table-view-cell.mui-collapse .mui-collapse-content{
				padding: 0px;
			}
			.weui_cell:before {
				left: 0px;
			}
			.big_chapter_div {
				margin-top: 10px;
			}
			.weui_panel {
				margin-top: 0;
			}
			.weui_cell {
				/*background-color: white;*/
			}
			.fen_ge_xian {
				height: 10px;
			}
			.chapter_title {
				margin-left: 4px;
			}
			.base_style_text_color .chapter_title{
				color: #18b4ed;
			}
			.base_content_font {
				font-size: 16px;
			}
			.base_tag_font {
				font-size: 14px;
			}
			.base_title_color_font {
				background-color: #f9f9f9;
			}
			.base_content_color_font {
				/*background-color: #FFFFFF;*/
			}
			.img_margin_left_1 {
				margin-left: 16px;
			}
			.img_margin_left_2 {
				margin-left: 32px;
			}
			.img_margin_left_3 {
				margin-left: 48px;
			}
			.img_margin_left_4 {
				margin-left: 64px;
			}
			.footer-view {
				position: fixed;
				left: 0;
				bottom: 0;
				margin: 0;
				width: 100%;
				height: 50px;
				padding: 0;
			}
			.footer-view .mui-btn-block {
				width: 100%;
				height: 100%;
				margin: 0;
				padding: 0;
				background-color: #ff9900;
				border-color: #ff9900;
				color: white;
				font-size: 16px;
			}
			.footer-view .mui-btn-block:active {
				background-color: #ff9900;
			}
			.mui-btn, button {
				border-radius: 0px;
				border-top-left-radius: 0px;
				border-top-right-radius: 0px;
				border-bottom-right-radius: 0px;
				border-bottom-left-radius: 0px;
			}
			.blank-div {
				height: 50px;
			}
			.mui-card {
			    box-shadow: 0px 0px 10px rgba(0,0,0,.1);
			}
			.section-chart{
				width: 80px;
				height: 80px;
			}
			.section-right-div{
				padding: 10px 20px 10px 20px; 
				/*height: 60px;*/
				float: right;
				width:-webkit-calc(100% - 80px); 
				width:-moz-calc(100% - 80px); 
				width:calc(100% - 80px); 
			}
			.section-title{
				display: -webkit-box;
				-webkit-box-orient: vertical;
				/*-webkit-line-clamp: 2;*/
				overflow: hidden;
				word-wrap: break-word;
			    white-space: normal; 
			}
			.cell-right-img{
				width: 20px;
			}
			.zhan-wei-div{
				height: 0;
			}
			.bottom-tiao{
				height: 20px;
			}
			.section-chart-mask{
				position: absolute;
				width: 80px;
				height: 80px;
				left: 15px;
				top: 11px;
			}
			.chapter-bg-content{
				background-color: #f0f0f0;
			}
			.base-content .mui-content>.mui-card:first-child{
				margin-top: 10px;
			}
			.base-content .mui-card{
				margin: 10px;
				border-color: #d5d5d5;
				border-radius: 0px;
				border-width: 0px;
			}
			.mui-card .mui-table-view .mui-table-view-cell:first-child, .mui-card .mui-table-view .mui-table-view-divider:first-child{
				border-top-left-radius: 0px;
			    border-top-right-radius: 0px; 
			}
			.mui-navigate-right{
				background-color: white;
			}
			.mui-navigate-right:active{
				background-color: white;
			}
			.cell-right-down{
				margin-left: 10px;
			}
			.folder-content{
				background-color: #f9f9f9;
			}
		</style>
		<link rel="stylesheet" type="text/css" href="../../css/chapterListBewrite.css">
	</head>
	<body>
		<div class="noSign noDataDiv" hidden="hidden" id="noData">
			<img src="../../image/icon_img.png" width="60%">
			<p class="font16 top_15 base_dark_grey" >
				暂无数据
			</p>
		</div>
		<div class="loadFailure noInternetDiv" hidden="hidden" id="noNet">
			<img src="../../image/icon_img01.png" width="60%">
			<p class="" >
				数据加载失败
			</p>
			<p>
				请检查您的网络
			</p>
			<button type="button" class="mui-btn mui-btn-outlined" onclick="loadChapterData()">
				重新加载
			</button>
		</div>
		<div class="base-content bgcolor">
			<div id="free_chapter_content">
				<!--  -->
				<!-- <div class="mui-content chapter-bg-content">
					<div class="mui-card">
						<ul class="mui-table-view">
							<li class="mui-table-view-cell mui-collapse">
								<a class="mui-navigate-right">
									<div class="section-right-div">
      									<p class="section-title base_dark_grey base_content_font">
											入库课程介绍
										</p>
      								</div>
      								<div id="chart" class="section-chart" style="background-color: red"></div>
      								<div class="section-chart-mask" style="background-color: yellow;"></div>
								</a>
								<div class="mui-collapse-content">
									<div class="weui_cell">
										<div class="weui_cell_hd">
											<img src="../../image/icon_taolun.png" alt="" class="chapter_cell_left_icon">
										</div>
										<div class="weui_cell_bd weui_cell_primary">
											<p class="base_dark_grey base_tag_font">
												<span>测验入库互动资源</span>
											</p>
										</div>
										<div class="weui-cell__ft">
											<img class="cell-right-img" src="../../image/icon_studied.png">
										</div>
									</div>
									<div class="weui_cell">
										<div class="bewrite-div">
											123412341
										</div>
									</div>
									<div class="bewrite-cell weui_cell">
										<div class="bewrite-div bewrite-div-min">
											<div class="bewrite-content">
												<p>
													奥斯卡到附近；拉斯科大姐夫；老师端分类考试的菲尼克斯带你飞；会计师带你飞会计师带你飞；可是当年发生的可能发；等级考试能否健康是电脑福利看你是否结束多年浪费空间你死定了
													奥斯卡到附近；拉斯科大姐夫；老师端分类考试的菲尼克斯带你飞；会计师带你飞会计师带你飞；可是当年发生的可能发；等级考试能否健康是电脑福利看你是否结束多年浪费空间你死定了
												</p>
												<img src="../../image/icon_nodata.png" width="100px;">
											</div>
											<div class="bewrite-bottom-hide" hidden="hidden">
												<span class="bewrite-bottom-span">
													收起
													<img class="icon-bewrite" src="../../image/icon_bewrite_up.png">
												</span>
											</div>
											<div class="bewrite-bottom-show">
												<span class="bewrite-bottom-span">
													展开更多
													<img class="icon-bewrite" src="../../image/icon_bewrite_down.png">
												</span>
											</div>
										</div>
									</div>
									<div id="" class="weui_cell sub_chapter_cell base_content_color_font">
										<div class="weui_cell_hd">
											<img src="../../image/010.png" alt="" class="chapter_cell_left_icon">
										</div>
										<div class="weui_cell_bd weui_cell_primary">
											<p class="base_dark_grey base_tag_font">
												<span class="chapter_title">去年买表</span>
											</p>
										</div>
										<div id="" class="weui-cell__ft">
											<img class="cell-right-img" src="../../image/icon_studied.png">
										</div>
										<div id="" class="weui-cell__ft cell-right-down">
											<img class="cell-right-img" src="../../image/icon_bewrite_down.png">
										</div>
									</div>
									<div class="folder-content">
										<div class="weui_cell base_content_color_font">
											<div class="weui_cell_hd">
												<img src="../../image/icon_chapter_pdf.png" alt="" class="chapter_cell_left_icon">
											</div>
											<div class="weui_cell_bd weui_cell_primary">
												<p class="base_dark_grey base_tag_font">
													<span class="chapter_title">去年买表</span>
												</p>
											</div>
										</div>
										<div class="weui_cell base_content_color_font">
											<div class="weui_cell_hd">
												<img src="../../image/icon_chapter_pdf.png" alt="" class="chapter_cell_left_icon">
											</div>
											<div class="weui_cell_bd weui_cell_primary">
												<p class="base_dark_grey base_tag_font">
													<span class="chapter_title">去年买表</span>
												</p>
											</div>
										</div>
									</div>
								</div>
							</li>
						</ul>
					</div>
				</div> -->
				<!--  -->
			</div>
			<div class="bottom-tiao"></div>
		</div>
		<div class="blank-div" hidden="hidden"></div>
		<div class="footer-view" hidden="hidden">
			<button id="study_btn" type="button" onclick="onExamClick()" class="mui-btn mui-btn-block"></button>
		</div>
	</body>
	<script type="text/javascript" src="../../script/echarts.min.js"></script>
	<script type="text/javascript" src="../../script/mui.min.js"></script>
	<script type="text/javascript" src="../../script/jquery.min.js"></script>
	<script type="text/javascript" src="../../script/api.js"></script>
	<script type="text/javascript" src="../../script/MD5.js"></script>
	<script type="text/javascript" src="../../script/requestTool.js"></script>
	<script type="text/javascript" src="../../script/common.js"></script>
	<script type="text/javascript" src="../../script/getToken.js"></script>
	<script type="text/javascript" src="../../script/push.js"></script>
	<script type="text/javascript" src="../../script/setupBewrite.js"></script>
	<script type="text/javascript" src="../../script/attachmentManager.js"></script>
	<script type="text/javascript" src="../../script/chapterFolder.js"></script>
	<script type="text/javascript">
		var chapterArr = new Array();
		var subChapterObjc = new Object();
		var type = 0;
		//判断是否是要重新加载 基数加载  偶数不加载
		var testNum = '';
		//测验章节考试次数
		var firstLoad = true;
		var open_type = '';
		//判断当前课程考核的状态
		var score_id = '';
		var score = '';
		apiready = function() {
			ReceNotifi();
			loadChapterData();
			setRefreshHeader();
			setupExamBtn();
			// startChapterUpdate();
			 SendBehaviorTrajectoriesNotifi(0, '章节列表', '028');
		}
		function setupChapterChart(chapterid){
			var param = {
				uid : $api.getStorage('cfnetppuid'),
				jid : $api.getStorage('cfnetppjxid'),
				cid : api.pageParam.courseid,
				pid : api.pageParam.planid,
				chapterid : chapterid
			};
			// alert('url:'+url_getSubChapterStudiedDetail+'\n'+JSON.stringify(param));
			cfnetppPOST(url_getSubChapterStudiedDetail, param, true, function(data, status){
				if (status == 'success') {
					if (data.code == 200) {
						var chartData = data.data;
						setupChart(chapterid, chartData);
					}else{
						setupChart(chapterid, null);
					}
				}else{
					setupChart(chapterid, null);
				}
			});
		}
		function setupChart(chapterid, data){
			var chartid = 'chart' + chapterid;
			var studiedNum;
			var unStudyNum;
			var percentage;
			var myChart = echarts.init(document.getElementById(chartid));
			if (data == null) {
				studiedNum = 0;
				unStudyNum = 1;
				percentage = '0%';//百分比
			}else{
				studiedNum = parseFloat(data.studiednum);
				var allNum = parseFloat(data.allchapternum);
				if (allNum < studiedNum) {
					allNum = studiedNum;
				}
				unStudyNum = allNum - studiedNum;
				percentageNum = (studiedNum / allNum) * 100;
				percentage = percentageNum.toFixed(0) + '%'; 
			}
			myChart.setOption({
				title: {
			        text: percentage,
			        x: 'center',
			        y: 'center',
			        textStyle:{
				        //文字颜色
				        color:'#666',
				        //字体风格,'normal','italic','oblique'
				        fontStyle:'normal',
				        //字体粗细 'normal','bold','bolder','lighter',100 | 200 | 300 | 400...
				        fontWeight:'bold',
				        //字体系列
				        fontFamily:'sans-serif',
				        //字体大小
				　　　　 fontSize:14
				    }
			    },
				series: [
				    {
				        type:'pie',
				        radius: ['70%', '100%'],
				        avoidLabelOverlap: true,
				        label: {
				            normal: {
				                show: true,
				                position: 'center'
				            },
				            emphasis: {
				                show: true
				            }
				        },
				        labelLine: {
				            normal: {
				                show: true
				            }
				        },
				        data:[
				            {value:studiedNum},
				            {value:unStudyNum}
				        ],
				        color:['#18b4ed', '#d0d0d0']
				    }
				]
			});
		}
		/*没有考试次数通过考试  1  
		 * 没有考试次数没通过考试 2  
		 * 又考试次数通过考试3 
		 * 有考试次数没通过考试4  
		 * 5  是  通过 考试 无限次的 
		 *  6是没有通过考试的
		 * 
		 * 
		 */
		function setupExamBtn() {
			var examid = api.pageParam.examid;
			
			var params = {
				exam_id : api.pageParam.examid,
				user_id : $api.getStorage('cfnetppuid'),
				cid : api.pageParam.courseid,
				pid : api.pageParam.planid
			};
			
			cfnetppPOST(url_getCourseExamType, params, true, function(data, status) {
//				alert('url' + JSON.stringify(params) + '\n' + JSON.stringify(data));
				api.refreshHeaderLoadDone();
				if (status == 'success') {
					if (data.code == 200) {
					var is_score = data.data[0].is_score;
					score_id = data.data[0].score_id;
					score = data.data[0].score;
					
					
						if (examid != undefined && examid != null && examid != '' && examid != "0"&& examid != 0) {
							if (is_score == 4 || is_score == 6) {//开始考试
								$("#study_btn").text("开始考试");
								open_type = 0;
							} else if (is_score == 1 || is_score == 2 || is_score == 3 || is_score == 5) {//查看考试结果
								$("#study_btn").text("查看考试结果");
								open_type = 1;
							}
							$(".blank-div").show();
							$(".footer-view").show();
						} else {
							$(".blank-div").hide();
							$(".footer-view").hide();
						}
					} else if (data.code == 108) {
					   if(examid != undefined && examid != null && examid != '' && examid != "0"&& examid != 0){
					      $(".blank-div").show();
						  $(".footer-view").show();
						  $("#study_btn").text("开始考试");
						  open_type = 0;
					   }else{
					      $(".blank-div").hide();
						  $(".footer-view").hide();
					      open_type = 1;
					   }
					} else {
						$(".blank-div").hide();
						$(".footer-view").hide();
					}
				} else {
					$(".blank-div").hide();
					$(".footer-view").hide();
				}
			});
		}

		function onExamClick() {
			api.openWin({useWKWebView:true,
				name : 'Student_CourseTestExam',
				url : 'Student_CourseTestExam.html',
				pageParam : {
					appkey : 148745497845,
					match_type : 3,
					exam_id : api.pageParam.examid,
					plan_id : api.pageParam.planid,
					course_id : api.pageParam.courseid,
					score_id : score_id,
					open_type : open_type,
					score : score,
				    type :1//自由课程
				}
			});
		}

		//下拉刷新
		function setRefreshHeader() {
			api.setRefreshHeaderInfo({
				visible : true,
				bgColor : '#ccc',
				textColor : '#fff',
				textDown : '下拉刷新...',
				textUp : '松开刷新...',
				showTime : true
			}, function(ret, err) {
				loadChapterData();
			});
		}

		function ReceNotifi() {
			api.addEventListener({
				name : 'RefreshCourseTestNotifi'
			}, function(ret, err) {
				setupExamBtn();
			});
			api.addEventListener({
				name : 'chapterUpdateNotifi'
			}, function(ret, err) {
				// loadChapterData();
			});
			// api.addEventListener({
			//     name: 'viewappear'
			// }, function(ret, err) {
			//     setupCharts();
			// });
			api.addEventListener({
			    name: 'freeCourseRecordNotifi'
			}, function(ret, err) {
			    var chapterid = ret.value.vid;
			    $('#chapterStatus'+chapterid).show();
			});
			//	    api.addEventListener({
			//		    name:'RefreshTestNotifi'
			//	    },function(ret,err){
			//	    firstLoad = true;
			//	    	loadChapterData();
			//	    });
		}
		function saveTimeStamp(){
	        var timestamp = new Date().getTime();
	        var timeStampStr = timestamp.toString();
	        $api.setStorage('chapterLastTimeStamp', timeStampStr);
	        $api.setStorage('chapterLastCourseId', api.pageParam.courseid);
	        $api.setStorage('chapterLastPlanId', api.pageParam.planid);
	    }
		function loadChapterData() {
			firstLoad = true;
			var params = {
				cid : api.pageParam.courseid
			};
			cfnetppPOST(url_freeChapterUrl, params, true, function(data, status) {
				api.refreshHeaderLoadDone();
				if (status == 'success') {
					if (data.status == true) {
						//存储最后刷新的一次时间戳
						saveTimeStamp();
						var chapterlist = data.data;
						if (chapterlist != null && chapterlist.constructor == Array && chapterlist.length > 0) {//判断章节数组是否有效
							chapterArr = chapterlist;
							setupChapterList();
							//设置章节列表
							$('.noDataDiv').hide();
							$('.noInternetDiv').hide();
						} else {
							$('.noDataDiv').show();
							$('.noInternetDiv').hide();
						}
					} else {
						api.toast({
							msg : '自由课程章节列表加载失败'
						});
						$('.noDataDiv').show();
						$('.noInternetDiv').hide();
					}
				} else {
					api.toast({
						msg : '自由课程章节列表加载失败'
					});
					$('.noDataDiv').hide();
					$('.noInternetDiv').show();
				}
			});
		}
		//设置第二子章节
		function setupChildChapterList(prefix, chapterid, type) {
			var params = {
				cid : api.pageParam.courseid,
				pid : chapterid,
				uid : $api.getStorage('cfnetppuid'),
				jhid : api.pageParam.planid,
				jid : $api.getStorage('cfnetppjxid')
			};
			// alert('url'+url_subChapterUrl+'\n'+JSON.stringify(params));
			cfnetppPOST(url_subChapterUrl, params, true, function(data, status) {
				// alert(JSON.stringify(data));
				if (status == 'success') {
					if (data.status == true) {
						var chapterlist = data.data;
						if (chapterlist != null && chapterlist.constructor == Array && chapterlist.length > 0) {//判断章节数组是否有效
							setupSubChapterList(prefix, chapterlist);
							//设置子章节列表
						}
					} else {
						// api.toast({
						//     msg: '自由课程章节列表加载失败'
						// });
					}
				} else {
					// api.toast({
					//     msg: '自由课程章节列表加载失败'
					// });
				}
			});
		}
		//设置第二子章节
		function setupChildChapterList_old(prefix, chapterid, type) {
			$('.div_after').hide();
			if ($(type).hasClass("class_none") || prefix == 1) {
				uploadChapterStudyRecord(chapterid);
				//上传章的学习记录
				if (prefix == 1) {
					if (firstLoad == true) {
						firstLoad = false;
					} else {
						$(type).next('.div_after').show();
						return;
					}
					$('#' + chapterid).removeClass("class_none");
				}
				var params = {
					cid : api.pageParam.courseid,
					pid : chapterid,
					uid : $api.getStorage('cfnetppuid'),
					jhid : api.pageParam.planid
				};
				// alert('url'+url_subChapterUrl+'\n'+JSON.stringify(params));
				cfnetppPOST(url_subChapterUrl, params, true, function(data, status) {
					// alert(JSON.stringify(data));
					if (status == 'success') {
						if (data.status == true) {
							var chapterlist = data.data;
							if (chapterlist != null && chapterlist.constructor == Array && chapterlist.length > 0) {//判断章节数组是否有效
								setupSubChapterList(prefix, chapterlist);
								//设置子章节列表
							}
						} else {
							// api.toast({
							//     msg: '自由课程章节列表加载失败'
							// });
						}
					} else {
						// api.toast({
						//     msg: '自由课程章节列表加载失败'
						// });
					}
				});
				$(type).removeClass("class_none");
			}
			// $(window).scrollTop(44);
			// $(type).next('.div_after').show('fast', function() {
			// });;
			$(type).next('.div_after').show();
			// $(type).next('.div_after').toggle();
		}

		//设置第三子章节列表
		function childsetupChildChapterList(prefix, chapterid) {
			var params = {
				cid : api.pageParam.courseid,
				pid : chapterid,
				uid : $api.getStorage('cfnetppuid'),
				jhid : api.pageParam.planid,
				jid : $api.getStorage('cfnetppjxid')
			};
			cfnetppPOST(url_subChapterUrl, params, true, function(data, status) {
				if (status == 'success') {
					if (data.status == true) {
						var chapterlist = data.data;
						if (chapterlist != null && chapterlist.constructor == Array && chapterlist.length > 0) {//判断章节数组是否有效
							setchildupSubChapterList(prefix, chapterlist);
							//设置子章节列表
						}
					} else {
						// api.toast({
						//     msg: '自由课程章节列表加载失败'
						// });
					}
				} else {
					// api.toast({
					//     msg: '自由课程章节列表加载失败'
					// });
				}
			});
		}
		function setupCharts(){
			for (var i = 0; i < chapterArr.length; i++) {
				var chapterData = chapterArr[i];
				setupChapterChart(chapterData.id);
			}
		}
		//设置章节列表
		function setupChapterList() {
			$('#free_chapter_content').html('');
			for (var i = 0; i < chapterArr.length; i++) {
				var chapterData = chapterArr[i];
				var chapterHtmlStr = sectionHtmlWithData(i + 1, chapterData);
				//			alert(chapterHtmlStr);
				$('#free_chapter_content').append(chapterHtmlStr);
				setupChapterChart(chapterData.id);//设置图表
				if (i == 0) {
					$('#section_tap'+chapterData.id).addClass('mui-active');
				}
				uploadChapterStudyRecord(chapterData.id);
				//拼接章html串
				// alert(JSON.stringify(chapterData));
				if (parseInt(chapterData.child) > 0) {
					setupChildChapterList(i + 1, chapterData.id);
				}
			}
			// setupSectionCellClick();
		}

		//设置第二子章节列表
		function setupSubChapterList(prefix, chapterlist) {
			// var chapterContainerId = '#container' + chapterlist[0].id;
			var subChapterHtmlStr = '';
			for (var i = 0; i < chapterlist.length; i++) {
				var chapterData = chapterlist[i];
				subChapterObjc[chapterData.id] = chapterData;
				subChapterHtmlStr += cellHtmlWithData(prefix, i + 1, chapterData);
				if (parseInt(chapterData.child) > 0) {
					childsetupChildChapterList(prefix + '.' + (i + 1), chapterData.id);
				}
			}
			$('#aft_chapterid' + chapterData.pid).after(subChapterHtmlStr);
			// $('#' + chapterData.pid).after('<div class="div_after">' + subChapterHtmlStr + '</div>');
			setSubChapterClick();
			setupBewriteClick();
		}

		//设置第三子章节列表
		function setchildupSubChapterList(prefix, chapterlist) {
			var subChapterHtmlStr = '';
			for (var i = 0; i < chapterlist.length; i++) {
				var chapterData = chapterlist[i];
				subChapterObjc[chapterData.id] = chapterData;
				subChapterHtmlStr += cellHtmlWithData(prefix, i + 1, chapterData);
				if (parseInt(chapterData.child) > 0) {
					childsetupChildChapterList(prefix + '.' + (i + 1), chapterData.id);
				}
			}
			$('#aft_chapterid' + chapterData.pid).after(subChapterHtmlStr);
			setSubChapterClick();
			setupBewriteClick();
		}
		function setupSectionCellClick(){
			// $('.section-cell').unbind('click');
			// $('.section-cell').on("click",function(){
			// 	var chapterid = $(this).attr('chapterid');
			// 	uploadChapterStudyRecord(chapterid);
			// });
			// $('.section-cell').unbind('click');
			// $('.section-cell').click(function(){
			// 	var chapterid = $(this).attr('chapterid');
			// 	alert(chapterid);
			// 	uploadChapterStudyRecord(chapterid);
			// });
		}
		function onSectionClick(chapterid){
			uploadChapterStudyRecord(chapterid);
		}
		function sectionHtmlWithData(index, data) {
			var isclose = data.isclose;
			if (isclose == '1') {
				return "";
			}
			var trainsObj = new GB2312UTF8();
			// '<div id="' + data.id + '" class="weui_cell  base_title_color_font class_none"  onclick="setupChildChapterList(' + index + "," + "'" + data.id + "'" + "," + 'this)">' + '<div class="weui_cell_bd weui_cell_primary">' + '<p class="base_dark_grey base_content_font">' +
			// // '<span>第'+index+'章</span>'+
			// '<span class="chapter_title">' + trainsObj.Utf8ToGb2312(data.cdetailtitle) + '</span>' + '</p>' + '</div>' + '</div>';
			// //	        '<div class="weui_cell fen_ge_xian"></div>  <div>';
			return '<div chapterid="'+data.id+'" index="'+index+'" class="mui-content chapter-bg-content section-cell">'+
					'<div class="mui-card">'+
						'<ul class="mui-table-view">'+
							'<li id="section_tap'+data.id+'" class="mui-table-view-cell mui-collapse">'+
								'<a class="mui-navigate-right">'+
									'<div class="section-right-div">'+
      									'<p class="section-title base_dark_grey base_content_font">'+
											trainsObj.Utf8ToGb2312(data.cdetailtitle)+
										'</p>'+
      								'</div>'+
      								'<div id="chart'+data.id+'" class="section-chart"></div>'+
      								'<div class="section-chart-mask"></div>'+
								'</a>'+
								'<div class="mui-collapse-content">'+
									'<div class="zhan-wei-div" id="aft_chapterid' + data.id + '">'+
								'</div>'+
							'</li>'+
						'</ul>'+
					'</div>'+
				'</div>';
		}
		function imagePathWithUrlPath(fileName){
			var fileSuffix = fileSuffixWithPath(fileName);
			if (fileSuffix == '.doc' || fileSuffix == '.docx') {
				return '../../image/icon_chapter_doc.png';
			}else if(fileSuffix == '.pdf'){
				return '../../image/icon_chapter_pdf.png';
			}else if(fileSuffix == '.xls' || fileSuffix == '.xlsx'){
				return '../../image/icon_chapter_excel.png';
			}else if(fileSuffix == '.ppt' || fileSuffix == '.pptx'){
				return '../../image/icon_chapter_ppt.png';
			}else if(fileSuffix == '.png' || fileSuffix == '.jpg' || fileSuffix == '.jpeg' || fileSuffix == '.bmp' || fileSuffix == '.gif'){
				return '../../image/icon_chapter_img.png';
			}else if(fileSuffix == '.mp4' || fileSuffix == '.avi' || fileSuffix == '.rmvb' || fileSuffix == '.3gp' || fileSuffix == '.flv'){
				return '../../image/09.png';
			}else{
				return '../../image/011.png';
			}
		}
		function fileSuffixWithPath(path){
			var result =/\.[^\.]+/.exec(path);
			return result;
		}
		function cellHtmlWithData(prefix, index, data) {
			var isclose = data.isclose;
			if (isclose == '1') {
				return "";
			}
			var content_type = data.content_type;
			var imgSrc = '';
			var folderRightImage = '';
			var folderContentDiv = '';
			if (content_type == 'richtext') {//富文本
				if (data.rid == '') {//富文本
					imgSrc = '../../image/08.png';
				} else {//视频
					imgSrc = '../../image/09.png';
				}
			} else if (content_type == 'survey') {//调查
				imgSrc = '../../image/03.png';
			} else if (content_type == 'tests') {//测验
				imgSrc = '../../image/01.png';
			} else if (content_type == 'discuss') {//讨论
				imgSrc = '../../image/02.png';
			} else if (content_type == 'works') {//作业
				imgSrc = '../../image/04.png';
			} else if (content_type == 'folder') {//文件夹
				imgSrc = '../../image/010.png';
				folderRightImage = '<div class="weui-cell__ft cell-right-down">'+
										'<img id="folder_right_img'+data.id+'" class="cell-right-img" src="../../image/icon_bewrite_down.png">'+
									'</div>';
				folderContentDiv = '<div id="folder_file_div'+data.id+'" class="folder-content"></div>';
			} else if (content_type == 'files') {//文件
				// imgSrc = '../../image/011.png';
				var rid = data.rid;
				var ridArr = rid.split('||');
				var fileName = ridArr[0];
				imgSrc = imagePathWithUrlPath(fileName);
			} else if (content_type == 'sitenow') {//现场实操
				imgSrc = '../../image/05.png';
			} else if (content_type == 'hdresource') {//互动资源
				imgSrc = '../../image/06.png';
			} else if (content_type == 'sysdeal') {//系统处理
				imgSrc = '../../image/icon_scorm.png';
			} else if (content_type == 'flash') {//flash动画
				imgSrc = '../../image/icon_flash.png';
			} else if (content_type == 'tag') {
				imgSrc = '../../image/07.png';
			} else {
				imgSrc = '../../image/icon_scorm.png';
			}
			var index_i = prefix + '.' + index;
			var preArr = index_i.split(".");
			var marginLeftClass = '';
			if (preArr.length == 0 || preArr.length == 1) {
			} else if (preArr.length == 2) {
				marginLeftClass = " img_margin_left_1";
			} else if (preArr.length == 3) {
				marginLeftClass = " img_margin_left_2";
			} else if (preArr.length == 4) {
				marginLeftClass = " img_margin_left_3";
			} else {
				marginLeftClass = " img_margin_left_4";
			}
			var chapterStatus = '<div id="chapterStatus'+data.id+'" class="weui-cell__ft" hidden="hidden">'+
									'<img class="cell-right-img" src="../../image/icon_studied.png">'+
								'</div>';
			if (data.status == 1) {
				chapterStatus = '<div id="chapterStatus'+data.id+'" class="weui-cell__ft">'+
									'<img class="cell-right-img" src="../../image/icon_studied.png">'+
								'</div>';
			}
			//描述
			var bwriteHtml = bewriteHtmlWithData(data);

			var afterHtml = '<div id="aft_chapterid'+data.id+'" hidden="hidden"></div>';
			// // onclick="setupChildChapterList(' + index_i +","+"'"+data.id+ "'"+","+"'"+1+ "'"+')"
			// return '<div id="' + data.id + '" class="weui_cell sub_chapter_cell base_content_color_font" >' + '<div class="weui_cell_hd' + marginLeftClass + '">' + '<img src="' + imgSrc + '" alt="" class="chapter_cell_left_icon">' + '</div>' + '<div class="weui_cell_bd weui_cell_primary">' + '<p class="base_grey base_tag_font">' +
			// // '<span>('+prefix+'.'+index+')</span>'+
			// '<span class="chapter_title">' + data.cdetailtitle + '</span>' + '</p>' + '</div>' + '</div>';
			return '<div id="' + data.id + '" class="weui_cell sub_chapter_cell base_content_color_font">'+
				'<div class="weui_cell_hd">'+
					'<img src="' + imgSrc + '" alt="" class="chapter_cell_left_icon">'+
				'</div>'+
				'<div class="weui_cell_bd weui_cell_primary">'+
					'<p class="base_dark_grey base_tag_font">'+
						'<span class="chapter_title">' + data.cdetailtitle + '</span>'+
					'</p>'+
				'</div>'+
				chapterStatus+
				folderRightImage+
			'</div>'+
			bwriteHtml+
			folderContentDiv+
			afterHtml;
		}

		function setSubChapterClick() {
			$('.sub_chapter_cell').unbind('click');
			$('.sub_chapter_cell').click(function() {
				$('.sub_chapter_cell').removeClass('base_style_text_color');
				$(this).addClass('base_style_text_color');
				var chapterid = $(this).attr('id');
				var subChapterData = subChapterObjc[chapterid];
				var content_type = subChapterData.content_type;
				if (content_type != 'survey' && content_type != 'tests' && content_type != 'discuss' && content_type != 'works' && content_type != 'sitenow') {
					uploadChapterStudyRecord(chapterid);//记录一次学习
				}
				pushToNextWindow(subChapterData);
			});
			$('.bewrite-cell').unbind('click');
			$('.bewrite-cell').click(function(){
				var chapterid = $(this).attr('chapterid');
				$('.sub_chapter_cell').removeClass('base_style_text_color');
				$('#'+chapterid).addClass('base_style_text_color');
				var subChapterData = subChapterObjc[chapterid];
				var content_type = subChapterData.content_type;
				if (content_type != 'survey' && content_type != 'tests' && content_type != 'discuss' && content_type != 'works' && content_type != 'sitenow') {
					uploadChapterStudyRecord(chapterid);//记录一次学习
				}
				pushToNextWindow(subChapterData);
				// var isTag = $(this).attr('isTag');
				// if (isTag != '1') {
					
				// }
			});
		}
		//上传章节学习记录
		function uploadChapterStudyRecord(vid) {
			api.sendEvent({
				name : 'freeCourseRecordNotifi',
				extra : {
					uid : $api.getStorage('cfnetppuid'),
					jid : $api.getStorage('cfnetppjxid'),
					cid : api.pageParam.courseid,
					vid : vid,
					pid : api.pageParam.planid
				}
			});
			setTimeout(function(){
				setupCharts();
			}, 1000);
		}

		//根据类型跳转页面
		function pushToNextWindow(data) {
			var pid = api.pageParam.planid;
			var cType = data.content_type;
			var winName = '';
			var isclose = data.isclose;
			var bewrite = data.bewrite;
			var is_encr = data.is_encr;
			var baidu_cloud_id_url = data.baidu_cloud_id_url;
			var baidu_cloud_id = data.baidu_cloud_id;
			data["cid"] = api.pageParam.courseid;
			if (isclose == '1') {
				api.toast({
					msg : '该课时尚未发布，暂不能学习',
					duration : 3000,
					location : 'bottom'
				});
				return;
			}
			var pageParam = new Object();
			if (cType == 'richtext') {//富文本
			
			    UploadAddChapterInformation(pid,data.id);
				//		   if(bewrite.length >0){
				//			  	winName = 'Student_Free_bewrite';
				//
				//			}else{
				if (data.rid == '') {//富文本
					winName = 'studyCourseRichtextNew';
				} else {//视频
					var connectionType = api.connectionType;
					if (connectionType != 'wifi' && connectionType != 'none') {
						api.confirm({
							title : '提示',
							msg : '您当前处于移动数据网络下，是否继续播放',
							buttons : ['确定', '取消']
						}, function(ret, err) {
							var index = ret.buttonIndex;
							if (index == 1) {//确定
								// toPlayVideo(data);
								pushToBaiDuPlayer(is_encr, baidu_cloud_id_url, data.rid, data.cdetailtitle);
							}
						});
					} else {
						// toPlayVideo(data);
						pushToBaiDuPlayer(is_encr, baidu_cloud_id_url, data.rid, data.cdetailtitle);
					}
					return;
				}
				//			}
				pageParam = {
					chapterid : data.id,
					cdetailtitle : data.cdetailtitle,
					richtextType : 1,
					other : data.other,
					bewrite : data.bewrite,
					is_dis_bewrite : data.is_dis_bewrite,
					content_type : cType,
					rid : data.rid
				};
			} else if (cType == 'survey') {//调查
				$api.setStorage('Research_title', data.cdetailtitle);
				// if (bewrite.length > 0) {
				// 	winName = 'Student_Free_bewrite';
				// } else {
					winName = 'New_Student_Study_ResearchExam';
				// }
				pageParam = {
					id : data.id,
					pid : pid,
					cid : data.cid,
					cdetailtitle : data.cdetailtitle,
					rid : data.rid,
					bewrite : data.bewrite,
					is_dis_bewrite : data.is_dis_bewrite,
					content_type : cType
				};
			} else if (cType == 'tests') {//测验
				$api.setStorage('Test_title', data.cdetailtitle);
				// if (bewrite.length > 0) {
				// 	winName = 'Student_Free_bewrite';
				// } else {
					winName = 'New_student_study_freecourse_TestExam';
				// }
				pageParam = {
					id : data.id,
					pid : pid,
					cid : data.cid,
					cdetailtitle : data.cdetailtitle,
					rid : data.rid,
					bewrite : data.bewrite,
					isanswer : data.isanswer,
					is_cy : data.is_cy,
					is_cypass : data.is_cypass,
					examnum : data.examnum,
					is_dis_bewrite : data.is_dis_bewrite,
					isteacher : 1,
					type : 1,
					content_type : cType
				};
			} else if (cType == 'discuss') {//讨论
				winName = 'New_Student_FreeCourse_DiscussChapterWindow';
				pageParam = {
					chapterid : data.id,
					pid : pid,
					cid : data.cid,
					cdetailtitle : data.cdetailtitle,
					bewrite : data.bewrite,
					is_dis_bewrite : data.is_dis_bewrite,
				};
			} else if (cType == 'works') {//作业
				winName = 'new_student_study_freecourse_homeworks';
				pageParam = {
					pid : pid,
					chapterid : data.id,
					cdetailtitle : data.cdetailtitle,
					bewrite : data.bewrite,
					is_dis_bewrite : data.is_dis_bewrite,
					cid : api.pageParam.courseid
				};
			} else if (cType == 'folder') {//文件夹
			   UploadAddChapterInformation(pid,data.id);
				// winName = 'Student_FreeCourseFileNew';
				// pageParam = data;
				setupFolderFCellClick(data.id);
				return;
			} else if (cType == 'files') {//文件
			  UploadAddChapterInformation(pid,data.id);
			    
				// winName = 'Student_FreeCourseFileNew';
				// pageParam = data;
				setupFilesChapter(data);
				return;
			} else if (cType == 'sitenow') {//现场实操
				// if (bewrite.length > 0) {
				// 	winName = 'Student_Free_bewrite';
				// 	pageParam = data;
				// 	pageParam["pid"] = pid;
				// } else {
					winName = 'new_Mark_sheet';
					pageParam = data;
					pageParam["pid"] = pid;
				// }
			} else if (cType == 'hdresource') {//互动资源
			    UploadAddChapterInformation(pid,data.id);
				// if (bewrite.length > 0) {
				// 	winName = 'Student_Free_bewrite';
				// 	pageParam = data;
				// } else {
					if (api.connectionType == 'none') {
						api.toast({
							msg : '暂无网络，无法访问该内容'
						});
						return;
					}
					winName = 'student_study_freecourse_interactiveNew';
					pageParam = data;
				// }
				pageParam["type"] = 1;
			} else if (cType == 'tag') {//标签
				// if (bewrite.length > 0) {
				// 	winName = 'Student_Free_bewrite';
				// 	pageParam = {
				// 		cdetailtitle : data.cdetailtitle,
				// 		bewrite : data.bewrite,
				// 		is_dis_bewrite : data.is_dis_bewrite,
				// 		path : data.url
				// 	};
				// } else {
				// 	api.toast({
				// 		msg : '该标签暂无描述内容',
				// 		duration : 3000,
				// 		location : 'bottom'
				// 	});
				// 	return;
				// }
				return;
			} else {
				api.toast({
					msg : '手机不支持该类型，请在电脑上查看'
				});
				return;
			}
			if (winName == 'New_student_study_freecourse_TestExam' || winName == 'New_Student_Study_ResearchExam') {
				api.openWin({useWKWebView:true,
					name : winName,
					url : winName + '.html',
					pageParam : pageParam,
					slidBackEnabled : false,
					softInputMode : 'pan',
				});
			} else {
				api.openWin({useWKWebView:true,
					name : winName,
					url : winName + '.html',
					pageParam : pageParam,
					slidBackEnabled : false
				});
			}
			SendBehaviorTrajectoriesNotifi(1, '章节列表', '028');
		}
		function setupFilesChapter(data){
			var is_encr = data.is_encr;
			var baidu_cloud_id_url = data.baidu_cloud_id_url;
			var baidu_cloud_id = data.baidu_cloud_id;
			var rid = data.rid;
			var ridArr = rid.split('||');
			var title = ridArr[0];
			var doc = ridArr[1];
			var arr = new Array('jpg', 'png', 'jpeg', 'bmp');
			var gifArr = new Array('gif');
			var arr1 = new Array('swf', 'mp4');
			var ext = doc.replace(/.+\./, "");
			if (gifArr.toString().indexOf(ext) > -1){
				openGif(doc);
			}else if (arr.toString().indexOf(ext) > -1) {
				openImage(doc);
			} else {
				if (arr1.toString().indexOf(ext) > -1) {
					var connectionType = api.connectionType;
		            if (connectionType != 'wifi' && connectionType != 'none') {
		            	api.confirm({
		                    title: '提示',
		                    msg: '您当前处于移动数据网络下，是否继续播放',
		                    buttons: ['确定', '取消']
		                }, function(ret, err) {
		                    var index = ret.buttonIndex;
		                    if (index == 1) {//确定
		                        // openVideoWin(doc, title);
		                        pushToBaiDuPlayer(is_encr, baidu_cloud_id_url, doc, title);
		                    }
		                });
		            }else{
		            	// openVideoWin(doc, title);
		            	pushToBaiDuPlayer(is_encr, baidu_cloud_id_url, doc, title);
		            }
				} else {
					if (is_encr == 1) {//加密
						var CFBaiDuDoc = api.require('CFBaiDuDoc');
				        CFBaiDuDoc.startDocActivityForResult({
				            docId:baidu_cloud_id,//文档ID
				            title:title,//文档标题
				            token:"TOKEN",//文档token，离线加载时不验证。
				            host:"BCEDOC",//文档所属站点
				            docType:"doc" //文档类型，可取值为ppt 和 doc
				        },function(){
				        });
					}else{
						api.openWin({useWKWebView:true,
							name : 'Student_FreeCourseDoc',
							url : 'Student_FreeCourseDoc.html',
							pageParam : {
								title : title,
								doc : doc
							}
						});
					}
				}
			}	
		
		}
		function toPlayVideo(data) {
			// api.confirm({
			//     title: '请选择播放器',
			//     buttons: ['阿里云播放器', '百度云播放器']
			// }, function(ret, err) {
			//     var index = ret.buttonIndex;
			//     if (index == 1) {
			//     	openALiWebVideo(data);
			//     }else{
			//     	openBaiDuWebVideo(data);
			//     }
			// });
			// return;
			// api.openWin({useWKWebView:true,
			//     name: 'Student_FreeCourseVideoPlayer',
			//     url: 'Student_FreeCourseVideoPlayer.html',
			//     pageParam: {
			//         videoUrl : data.rid,
			//         title : data.cdetailtitle
			//     }
			// });
			// var h = 240;
			// api.openFrame({
			//     name: 'HTML5VideoPlayer',
			//     url: '../Teacher_Teach/HTML5VideoPlayer.html',
			//     rect: {
			//         x: 0,
			//         y: 0,
			//         w: 'auto',
			//         h: h
			//     },
			//     pageParam:{
			//     	videoUrl : data.rid
			//     },
			//     reload : true
			// });
			// return;
			var videoPlayer = api.require('videoPlayer');
			videoPlayer.play({
				path : data.rid,
				texts : {
					head : {
						title : data.cdetailtitle
					}
				},
				styles : {
					head : {
						backSize : 24,
						backImg : 'widget://image/vp_back.png',
						setSize : 24,
						setImg : 'widget://image/vp_more.png'
					},
					foot : {
						playSize : 24,
						playImg : 'widget://image/vp_play.png',
						pauseImg : 'widget://image/vp_pause.png',
						nextSize : 24,
						nextImg : 'widget://image/vp_next.png'
					}
				}
			}, function(ret, err) {
			});
		}

		function openALiWebVideo(data) {
			var height = api.winHeight - 44;
			api.openFrame({
				name : 'ALiWebVideo',
				url : 'ALiWebVideo.html',
				rect : {
					x : 0,
					y : 44,
					w : 'auto',
					h : height
				},
				pageParam : {
					videoUrl : data.rid,
					title : data.cdetailtitle
				},
				bounces : false
			});
		}

		function openBaiDuWebVideo(data) {
			var width = api.winWidth;
			var height = width * 3 / 4;
			api.openFrame({
				name : 'BaiDuWebVideo',
				url : 'BaiDuWebVideo.html',
				rect : {
					x : 0,
					y : 44,
					w : 'auto',
					h : height
				},
				pageParam : {
					videoUrl : data.rid,
					title : data.cdetailtitle
				},
				bounces : false
			});
		}
		// 资源类上传操作
     function UploadAddChapterInformation(pid,id){
     // 资源类上传操作
		    api.sendEvent({
			    name: 'AddChapterInformation',
			    extra: {
			        pid : pid,
			        cid : api.pageParam.courseid,
			        vid :id
			    }
             });
     }
	</script>
</html>